package org.rency.mq.activemq.utils;

import javax.jms.DeliveryMode;
import javax.jms.Session;
import java.util.Map;

public class JsonMessageUtils {
	
	public static int getDeliveryMode(Map<String, Object> jsonMessageMap){
		if(jsonMessageMap.containsKey("deliveryMode")){
			return (Integer) jsonMessageMap.get("deliveryMode");
		}else{
			int deliveryMode = (Integer) jsonMessageMap.get("DeliveryMode");
			if(deliveryMode == 0) return DeliveryMode.PERSISTENT;
			return deliveryMode;
		}
	}
	
	public static int getAcknowledgeMode(Map<String, Object> jsonMessageMap){
		if(jsonMessageMap.containsKey("acknowledgeMode")){
			return (Integer) jsonMessageMap.get("acknowledgeMode");
		}else{
			int acknowledgeMode = (Integer) jsonMessageMap.get("AcknowledgeMode") + 1;
			
			if(acknowledgeMode == 4){
				acknowledgeMode = Session.SESSION_TRANSACTED;
			}else if(acknowledgeMode == 5){
				acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
			}
			return acknowledgeMode;
		}
	}

}
